const getCurrentPage = function () {
    const pages = getCurrentPages();
    return pages[pages.length - 1];
};

Component({
    options: {
        styleIsolation: 'shared',
    },
    properties: {
        active: {
            type: [Number, String],
            value: 0,
        },
        isHidden: {
            type: [Number, String],
            value: 0,
        },
        placeholder: {
            type: Boolean,
            value: true,
        },
    },
    pageObj: null,
    data: {
        showReceiveSuccessPopup: false,
        receiveSuccessTitle: '',
    },

    lifetimes: {
        attached() {
            const pages = getCurrentPages();
            this.pageObj = pages[pages.length - 1];
        },
    },

    methods: {
        onChange(e) {
            const active = e.detail.value;
            wx.switchTab({
                url: ['/pages/index/index', '/pages/cart/cart', '/pages/wallet/wallet', '/pages/user/user'][active],
            });
        },

        closeReceiveSuccessPopup() {
            this.setData({ showReceiveSuccessPopup: false, receiveSuccessTitle: '' });
            getCurrentPage().onShow();
        },
    },
});
